package com.zzxy.spring12.po;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

/**
 * 1.instantiate bean对象实例化
 * 2.populate properties 封装属性
 * 3.如果Bean实现BeanNameAware 执行 setBeanName
 * 4.如果Bean实现BeanFactoryAware 执行setBeanFactory ，获取Spring容器
 * 5.如果存在类实现 BeanPostProcessor（后处理Bean） ，执行postProcessBeforeInitialization
 * 6.如果Bean实现InitializingBean 执行 afterPropertiesSet
 * 7.调用<bean init-method="init"> 指定初始化方法 init
 * 8.如果存在类实现 BeanPostProcessor（处理Bean） ，执行postProcessAfterInitialization
 * 执行业务处理
 * 9.如果Bean实现 DisposableBean 执行 destroy
 * 10.调用<bean destroy-method="customerDestroy"> 指定销毁方法 customerDestroy
 */
public class User implements BeanNameAware, BeanFactoryAware , InitializingBean, DisposableBean {
    private String username;
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        System.out.println("2. set properties ...");
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public User() {
        System.out.println("1.init  bean ...");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("3. set bean name " + s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4.set bean factory ...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("6. after properties ...");
    }

    public void myInit() {
        System.out.println("7. custom init func ...");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9. destroy ...");
    }

    public void myDestroy() {
        System.out.println("10. custom destroy func ...");
    }
}
